<?php
/**
 * beimuaihui System
 * Copyright(c) 2011-2020 beimuaihui.
 * @license    http://www.gnu.org/licenses/gpl.html     This software Under GPL V3 License 
 * beimuaihui@gmail.com
 * http://code.google.com/p/beimuaihui/
 * $Id: Category.php 262 2011-07-23 15:51:14Z beimuaihui $
 */


Zend_Loader::loadClass("Baogg_Db_Table");

//class Permission extends Baogg_Db_Table {
class Category  extends Baogg_Db_Table {
	/**
	 * The default table name 
	 */
	protected $_name;
	protected $_db ;
	protected $_primary; 
	
	function __construct() {
		$this->_name =   'category';
		
		$this->primary= $this->_primary='category_id';
		parent::__construct();
		$this->updatePids();
	}
	
	
	 

	function getSame($arr) {	
		$ret=array();
		
		return parent::getSame2(array("category_name"=>$arr['category_name'],"category_pid"=>$arr['category_pid'])," and ");
	   
	
	}
	
	function updatePids()
    {
    	$pid=0;$pid_value=',';$pid_col='category_pid';
    	$this->_db->query("UPDATE {$this->_name} SET {$pid_col}s=''");
    	$this->_db->query("UPDATE {$this->_name} SET {$pid_col}s=concat('{$pid_value}',{$this->myPrimary},',') WHERE {$pid_col}={$pid}");
    	while($this->_db->query("UPDATE {$this->_name} a
					  JOIN {$this->_name} b
					    ON a.{$pid_col} = b.{$this->myPrimary}
					SET a.{$pid_col}s = CONCAT(b.{$pid_col}s,a.{$this->myPrimary},',')
					WHERE b.{$pid_col}s != '' and a.{$pid_col}s=''")->rowCount()){
		}
		
		return true;
    }
    
    function getNamesByPids($ids=array()){
    	$ret=array();
    	
    	if(!is_array($ids)){
    		$ids=explode(",",$ids);
    	}
		//$ids=array_reverse($ids);
    	$arr_ids=array_filter($ids);
    	foreach((array)$arr_ids as $v){
    		$rs=$this->getone($v);
    		$ret[$v]=@$rs[0]['category_name'];
    	}
    	return $ret;
    }

}
